home *** CD-ROM | disk | FTP | other *** search
/ New Masters of Flash / New Masters of Flash.iso / pc / MOVIES / 16.dir / 00284_Text_text21.txt < prev    next >
Text File  |  2000-10-01  |  8KB  |  179 lines

  1. while (loopage<9) {
  2.     if (eval ( "/F" add loopage add ":updown" ) == 1) {
  3.         if ("F" add loopage ne queenname1) {
  4.             queennum = queennum+1;
  5.             set ("queenname" add queennum, "F" add loopage);
  6.         }
  7.     }
  8.     loopage = loopage+1;
  9. }
  10. loopage = 1;
  11. while (loopage<9) {
  12.     if (eval ( "/G" add loopage add ":updown" ) == 1) {
  13.         if ("G" add loopage ne queenname1) {
  14.             queennum = queennum+1;
  15.             set ("queenname" add queennum, "G" add loopage);
  16.         }
  17.     }
  18.     loopage = loopage+1;
  19. }
  20. loopage = 1;
  21. while (loopage<9) {
  22.     if (eval ( "/H" add loopage add ":updown" ) == 1) {
  23.         if ("H" add loopage ne queenname1) {
  24.             queennum = queennum+1;
  25.             set ("queenname" add queennum, "H" add loopage);
  26.         }
  27.     }
  28.     loopage = loopage+1;
  29. }
  30.  
  31. What we did there was simply detect which queens are up. WeΓÇÖre faking arrays in Flash by using variables with numbers at the end of their names, so we can rotate through numbers and change variables. These are the first few lines of the code you just typed:
  32.  
  33. loopage = 1;
  34.  
  35. Prepares the loop.
  36.  
  37. queennum = 1;
  38.  
  39. Set queennum to 1 since the button the person just clicked sets queenname1 to the current queen and we donΓÇÖt want to overwrite it. This will make more sense in a minute:
  40.  
  41. while (loopage < 9) {
  42.  
  43.  Loop until loopage (which is one now) is less than 9.
  44.  
  45. if (eval ( ΓÇ£/AΓÇ¥ add loopage add ΓÇ¥:updownΓÇ¥ ) == 1) {
  46.  
  47. Remember the variable in the queenΓÇÖs movie clips that sets the variable updown to 1 if the queen is up, and to 0 when itΓÇÖs down. This is checking that. ΓÇ£/AΓÇ¥ add loopage add ΓÇ¥:updownΓÇ¥ when the loop first starts is equal to /A1:updown. This is the variable in the movie instance A1 called updown. Each of the movies has this variable set in it. As we move through this loop we check A2:updown, then A3:updown, and every time itΓÇÖs 1, which means the queen is up, the following commands happen:
  48.  
  49. if (ΓÇ£AΓÇ¥ add loopage NE queenname1) {
  50. Skip the queen that was just clicked. I just think it works better if the queen you put down stays and all the others go.
  51.  
  52. queennum = queennum+1 
  53.  
  54. Increase the number of queens that are up. The first time through this loop queennum equals 1 so this would make it now equal to 2.
  55.  
  56. set (ΓÇ£queennameΓÇ¥ add queennum, ΓÇ£AΓÇ¥ add loopage);
  57.  
  58. This sets the variable queenname2 to equal the grid number of the queen that is up. 
  59.  
  60. loopage = loopage + 1 
  61.  
  62. This increases the loopage number so that we can check all the queen movies in the A row. Once this number gets to 9 the loop condition is satisfied and stops the loop, and the code continues on.
  63.  
  64. This process is just repeated for the B,C,D,E,F,G, and H rows. After this is all done the Flash Movie has a list of all the queens that are up. If there are now FIVE queens up then there are five variables set. queenname1, queenname2, queenname3, queenname4, and queenname5. Each of these variables has the grid position of the queen in them.
  65.  
  66. Now you must add the code to remove queens that are being attacked by the new queen. In the same frame that you just put the code above, add the following BELOW it (the explanation follows):
  67. if (queennum>1) {
  68.     holder1 = queenname1;
  69.     holder2 = eval("queenname" add queennum);
  70.     queenname1 = holder2;
  71.     set ("queenname" add queennum, holder1);
  72. }
  73. loopage = queennum;
  74. xname2 = substring (eval("queenname" add loopage), 2, 1 );
  75. yname2 = substring (eval("queenname" add loopage), 1, 1 );
  76. queenx = eval ("s" add xname2 add "pos" );
  77. queeny = eval ( yname2 add "pos" );
  78. checkloop = loopage-1;
  79. while (checkloop)>0) {
  80.     xname = substring (eval("queenname" add checkloop), 2, 1 );
  81.     yname = substring (eval("queenname" add checkloop), 1, 1 );
  82.     checkx = eval( "s" add xname add "pos");
  83.     checky = eval ( yname add "pos");
  84.     if (checkx == queenx) {
  85.         // annnnnnnt
  86.         tellTarget (eval("queenname" add checkloop)) {
  87.             play ();
  88.         }
  89.     }
  90.     if (checky == queeny) {
  91.         // annnnnnnt
  92.         tellTarget (eval("queenname" add checkloop)) {
  93.             play ();
  94.         }
  95.     }
  96.     xdiff = queenx-checkx;
  97.     ydiff = queeny-checky;
  98.     xdiff = xdiff*xdiff;
  99.     ydiff = ydiff*ydiff;
  100.     if (xdiff == ydiff) {
  101.         // annnnnnnt
  102.         tellTarget (eval("queenname" add checkloop)) {
  103.             play ();
  104.         }
  105.     }
  106.     checkloop = checkloop-1;
  107. }
  108. Now let me explain what each piece of this code does:
  109.  
  110. if (queennum > 1) {
  111.   holder1 = queenname1;
  112.   holder2 = eval(ΓÇ£queennameΓÇ¥ add queennum);
  113.   queenname1 = holder2;
  114.   set (ΓÇ£queennameΓÇ¥ add queennum, holder1);
  115. }
  116.  
  117. This just reverses queenname1 and ΓÇ£queennameΓÇ¥ add queennum, which is the last queen in the set. This illustrates nicely my point about not writing your code when youΓÇÖre drunk. It might seem a bit pointless, but the code below uses the last queen to start the checking and we want the queen that was just placed to stay so we needed to reverse them. Oh well.
  118.  
  119. loopage = queennum;
  120.  
  121. We need to check all the queens except the one that was just placed down.
  122.  
  123. xname2 = substring (eval(ΓÇ£queennameΓÇ¥ add loopage), 2, 1 );
  124. yname2 = substring (eval(ΓÇ£queennameΓÇ¥ add loopage), 1, 1 );
  125.  
  126. This sets xname2 to the NUMBER in the grid coordinate of the placed queen, and yname2 to the LETTER in the grid coordinate of the placed queen.
  127.  
  128. queenx = eval(ΓÇ£sΓÇ¥ add xname2 add ΓÇ£posΓÇ¥  );
  129. queeny = eval( yname2 add ΓÇ£posΓÇ¥  );
  130.  
  131. This sets queenx and queeny to the number system we need to use for the Cartesian plane. Remember those variables that were set in the first frame of the movie? This gets the number values for the letters. 
  132. while (checkloop > 0) {
  133.  
  134. Loop through all the standing queens.
  135.  
  136. xname = substring (eval(ΓÇ£queennameΓÇ¥ add checkloop), 2, 1 );
  137. yname = substring (eval(ΓÇ£queennameΓÇ¥ add checkloop), 1, 1 );
  138. checkx = eval( ΓÇ£sΓÇ¥ add xname add ΓÇ£posΓÇ¥);
  139. checky = eval ( yname add ΓÇ£posΓÇ¥);
  140.  
  141. Get Cartesian coordinates of the queen currently being checked.
  142.  
  143. if (checkx == queenx) {
  144.   // annnnnnnt
  145.   tellTarget (eval(ΓÇ£queennameΓÇ¥ add checkloop)) {
  146.     play ();
  147.   }
  148.   
  149. If the queen being checked has the same x value of the placed queen then it is inline and being attacked. Tell Target that movie to play, which will lower that queen. (Note the comment, annnnnnnt which is pronounced like the ΓÇ£incorrectΓÇ¥ buzzer of a game show).
  150. if (checky == queeny) {
  151.   // annnnnnnt
  152.   tellTarget (eval(ΓÇ£queennameΓÇ¥ add checkloop)) {
  153.     play ();
  154.   }
  155. }
  156.  
  157. If the queen being checked has the same Y value of the placed queen then it is in line and being attacked. Annnnnnnt!
  158.  
  159. xdiff = queenx-checkx;
  160. ydiff = queeny-checky;
  161. xdiff = xdiff*xdiff;
  162. ydiff = ydiff*ydiff;
  163. if (xdiff == ydiff) {
  164.   // annnnnnnt
  165.   tellTarget (eval(ΓÇ£queennameΓÇ¥ add checkloop)) {
  166.     play ();
  167.   }
  168. }
  169.  
  170. This is the code to check the diagonals. ItΓÇÖs a bit of geometric math. Now, bear with me. Queens attacking along a diagonal are in a square. The code takes advantage of this. Look at the example. The x of the top queen is 3, the bottom one is 6. The code xdiff = queenxΓÇöcheckx would set the xdiff to ΓÇö3. (3 ΓÇö 6 = -3). The y of the top queen is 3, the bottom 6. The code ydiff = queenyΓÇöchecky would also produce a ΓÇö3.
  171.  
  172. Then it squares them with the lines xdiff = xdiff*xdiff and ydiff = ydiff*ydiff so now, xdiff = 9 and ydiff = 9.
  173.  
  174. If xdiff = ydiff then ANNNNNNNT since we know itΓÇÖs on the diagonal.
  175. Then the rest of the code just finished the loop until it checks every standing queen:
  176.  
  177. checkloop = checkloop-1;
  178. }
  179.